class Heap(list):
    
    # FIXME 代码不能用，需修改

    def __init__(self, arr=None):
        if arr is None:
            self._data = []
        else:
            self._data = arr.copy()
        for i in range(len(arr)):
            while i:
                if self._data[i] < self._data[i//2]:
                    self._data[i], self._data[i//2] = self._data[i//2], self._data[i]
                i = i//2
    
    def __swap(self, a,b):
        self._data[a], self._data[b] = self._data[b], self._data[a]
    
    def __repr__(self):
        return self._data.__repr__()

    def insert(self, num):
        i = len(self._data)
        self._data.append(num)
        while i:
            if self._data[i] < self._data[i//2]:
                self._data[i], self._data[i//2] = self._data[i//2], self._data[i]
            i = i//2
    
    def pop(self):
        pass

    def top(self):
        return self._data[0]

if __name__ == '__main__':
    '''h = Heap([6,5,4,3,2,1])
    print(h._data)
    h.insert(0)
    print(h._data)
    print(h)'''
    import random
    arr = list(range(8))
    random.shuffle(arr)
    heap_sort(arr)